package com.red.dubboprovider.service;

import com.red.dubbocommon.UserService;
import org.apache.dubbo.common.stream.StreamObserver;
import org.apache.dubbo.config.annotation.DubboService;

@DubboService(version = "1.0")
public class UserServiceImpl implements UserService {

    @Override
    public String getUser(){
        return "red-1";
    }

    @Override
    public void sayHelloServerStream(String name, StreamObserver<String> response) {
        // 处理name
        response.onNext("hello:"+name);
        // 可以再处理，再响应
        response.onNext("hello"+name);
        response.onCompleted();
    }

    @Override
    public StreamObserver<String> sayHelloStream(StreamObserver<String> response) {
        return new StreamObserver<String>() {
            @Override
            public void onNext(String data) {
                System.out.println("服务端接收到的数据"+data);
                // 处理data
                response.onNext("收到"+data);
            }

            @Override
            public void onError(Throwable throwable) {

            }

            @Override
            public void onCompleted() {
                System.out.println("发送完成");
            }
        };
    }
}
